<script>
var lineSegIndex = <#if lineseg_list?? && lineseg_list?size gt 0>${lineseg_list?size}<#else>0</#if>;
function addLineSeg() {
	lineSegIndex++;
	var tr = document.createElement('tr');
	tr.id='${field.name}tr'+lineSegIndex;
	$(tr).attr('class','listviewTR linesegtr');
	var html = '';
	html+="<td class=\"listviewTD\" align=\"right\"><span style=\"color:red;\">*</span>单位:</td>";
	html+="<td class=\"listviewContent\" align=\"left\">";
	html+="<input type=\"text\" class=\"textTest\" readonly=\"readonly\" name=\"lineSegRegionName"+lineSegIndex+"\" id=\"lineSegRegionName"+lineSegIndex+"\" datarule=\"string\" datarulejson='{\"displayName\":\"分段地区\",\"dataType\":\"string\",\"isRequired\":\"1\"}'>";
	html+="<input type=\"hidden\" name=\"fieldMap['${field.name}'].assistantCompanyList["+lineSegIndex+"].company.id\" id=\"lineSegRegionId"+lineSegIndex+"\">";
	html+="<div id=\"lineSegRegionDropdownMenu"+lineSegIndex+"\" class=\"dropDD_contentDiv\">";
	html+="<div style=\"overflow:auto;height:266px\">";
	html+="<ul id=\"lingSegRegionTree"+lineSegIndex+"\" class=\"tree\"></ul>";
	html+="</div>";
	html+="<div class=\"buttonBox\" style=\"position:absolute;bottom:0px;background:#f3f4f4;height:30px;padding-top:4px\">";
	html+="<a href=\"javascript:void(0);\" class=\"button\" tabindex=\"-1\"><input type=\"button\" onclick=\"window.curDDWin.saveWin();return false;\" value=\"确认\"></a>";
	html+="<a href=\"javascript:void(0);\" class=\"button\" tabindex=\"-1\"><input type=\"button\" onclick=\"lineSegRegionTreeclear('"+lineSegIndex+"');return false;\" value=\"清空\"></a>";
	html+="</div>";
  html+="</div>";
	html+="</td>";
	html+="<td class=\"listviewTD\" align=\"right\"><span style=\"color:red;\">*</span>线路长度:</td>";
	html+="<td class=\"listviewContent\" align=\"left\">";
	html+="<input type=\"text\" class=\"text\" style=\"width:133px;\" name=\"fieldMap['${field.name}'].assistantCompanyList["+lineSegIndex+"].length\" datarule=\"number\" datarulejson='{\"displayName\":\"分段长度\",\"dataType\":\"number\",\"precision\":\"6\",\"isRequired\":\"1\",\"length\":\"8\"}' >";
	html+="&nbsp;&nbsp;km</td>";
	html+="<td class=\"listviewContent\" colspan=\"1\" align=\"right\" style=\"padding-left:10px;\"><a href=\"javascript:void(0);\" onclick=\"removeLineSeg('"+lineSegIndex+"');return false;\">删除</a></td>";
	html+="<td class=\"listviewContent\" colspan=\"1\" align=\"left\">&nbsp;</td>";
	$(tr).html(html);
	var trArray = $('.linesegtr');
	$(tr).insertBefore($(trArray[trArray.length-1]));
	eval("var clickFunc = function(event,treeId,treeNode){$(document.getElementById('lineSegRegionName"+lineSegIndex+"')).val(treeNode.name);$(document.getElementById('lineSegRegionId"+lineSegIndex+"')).val(treeNode.id);window.curDDWin.saveWin();}");
	var setting = {
			asyncUrl : TDQS.CONTEXT_PATH+"company/equaltree.action",//获取平级单位树
			asyncParam : ["id"],
			async : true,
			callback : {
				click : clickFunc,
				loadTreeSuccess : function(zTree, msg) {		
					//zTree.expandAll();
				}
			}
		};
	eval("var operFun = function(){$(\"input[type='button']\",$('.dropDD_contentDiv')).each(function(){this.style.backgroundImage=\"url(./../theme/default/images/main/btn_normal.png)\";$(this).hover(function(){this.style.backgroundImage=\"url(./../theme/default/images/main/btn_over.png)\";},function(){this.style.backgroundImage=\"url(./../theme/default/images/main/btn_normal.png)\";});});new DDWin({el:'lineSegRegionDropdownMenu"+lineSegIndex+"',dep:'divAround_lineSegRegionName"+lineSegIndex+"',clickBody:'save'});}");
	$(document.getElementById('lingSegRegionTree'+lineSegIndex)).zTree(setting);
	$(document.getElementById('lineSegRegionName'+lineSegIndex)).inputStyle({
		operatorId:"lineSegRegionMenuBtn"+lineSegIndex,
		operatorType:"text",
		operatorText:"选择",
		controllerWidth:'133',
		operatorFun:operFun,
		imgFun:function(){
				lineSegRegionTreeclear(lineSegIndex);
				window.curDDWin.saveWin();
			}
	});
	$("input[datarule='number']",'.linesegtr').each(function(){
		var optionRule = {};
		optionRule["validatelinelength"] = true;				
		$(this).rules("add", optionRule);
	});
	validatorForm();
}
function lineSegRegionTreeclear(index) {
	$(document.getElementById('lineSegRegionName'+index)).attr("value", "");
	$(document.getElementById('lineSegRegionId'+index)).attr("value", "");
}
function removeLineSeg(index) {
	$(document.getElementById('${field.name}tr'+index)).remove();
	validatorForm();
}

addLoadEvent(function() {
	$.validator.addMethod("validatelinelength",function(value,element,params){
		var yearArray = $("input[datarule='number']",'.linesegtr');
		var value = Number($(element).val());
		var currentTotalLength = Number(null);
		for(var i=0;i<yearArray.length;i++) {
			var evalCost = yearArray[i];
			currentTotalLength = currentTotalLength + Number($(evalCost).val());
		}
		if(Number(currentTotalLength)>$("#planLineLength").val()){
			return false;
		}else{
			return true;
		}
	},'协办单位线路长度总和不能大于线路建设规模！');
	$("input[datarule='number']",'.linesegtr').each(function(){
		var optionRule = {};
		optionRule["validatelinelength"] = true;				
		$(this).rules("add", optionRule);
	});
	validatorForm();
})
</script>

<input type=hidden name="fieldMap['${field.name}'].id"  <#if businessInstanceField?? && businessInstanceField.id??>value="${businessInstanceField.id}"</#if>>
<input type=hidden name="fieldMap['${field.name}'].field.id"  value="${formField.field.id}">

<#if formField.readonly?? && formField.readonly=="1">
	<input type=hidden id=${field.name} name="fieldMap['${field.name}'].value" <#if businessInstanceField??>value="${businessInstanceField.value?default('')}"</#if>></input>
	
	<#if lineseg_list?? && lineseg_list?size gt 0>
		<#assign index=1>
		<#assign assistantCompany_yes = false>
		<#list lineseg_list as lineseg>
			<#if belong_user_company_id == lineseg.company.id && isVirtualProject?? && isVirtualProject== "1">
				<tr id="${field.name}tr${index}" class="listviewTR linesegtr">
					<td class="listviewTD" align="right">
						<input type="hidden" name="fieldMap['${field.name}'].assistantCompanyList[${index}].id" value="${lineseg.id?default('')}">
						单位:
					</td>
					<td class="listviewContent" align="left">
						${lineseg.company.name?default('')}
						<input type="hidden" name="fieldMap['${field.name}'].assistantCompanyList[${index}].company.id" id="lineSegRegionId${index}" value="<#if lineseg?? && lineseg.company??>${lineseg.company.id?default('')}</#if>">
					</td>
					<td class="listviewTD" align="right">
						线路长度:
					</td>
					<td class="listviewContent" align="left">
						<input type="hidden" class="text" style="width:133px;" name="fieldMap['${field.name}'].assistantCompanyList[${index}].length" <#if lineseg.length??>value="${lineseg.length?c}"</#if> >
						${lineseg.length?default('')}&nbsp;&nbsp;km
					</td>
					<td class="listviewContent" colspan="2" >&nbsp;</td>
				</tr>
				<#assign assistantCompany_yes = true>
				<#break>
			</#if>
			<#assign index=index+1>
		</#list>
		<#if !assistantCompany_yes>
			<#assign index=1>
			<#list lineseg_list as lineseg>
				<tr id="${field.name}tr${index}" class="listviewTR linesegtr">
					<td class="listviewTD" align="right">
						<input type="hidden" name="fieldMap['${field.name}'].assistantCompanyList[${index}].id" value="${lineseg.id?default('')}">
						单位:
					</td>
					<td class="listviewContent" align="left">
						${lineseg.company.name?default('')}
						<input type="hidden" name="fieldMap['${field.name}'].assistantCompanyList[${index}].company.id" id="lineSegRegionId${index}" value="<#if lineseg?? && lineseg.company??>${lineseg.company.id?default('')}</#if>">
					</td>
					<td class="listviewTD" align="right">
						线路长度:
					</td>
					<td class="listviewContent" align="left">
						<input type="hidden" class="text" style="width:133px;" name="fieldMap['${field.name}'].assistantCompanyList[${index}].length" <#if lineseg.length??>value="${lineseg.length?c}"</#if> >
						${lineseg.length?default('')}&nbsp;&nbsp;km
					</td>
					<td class="listviewContent" colspan="2" >&nbsp;</td>
				</tr>
			<#assign index=index+1>
			</#list>
		</#if>
	</#if>	
<#else>

<#if lineseg_list?? && lineseg_list?size gt 0>
	<#assign index=1>
	<#list lineseg_list as lineseg>
	<tr id="${field.name}tr${index}" class="listviewTR linesegtr">
	<input type="hidden" name="fieldMap['${field.name}'].assistantCompanyList[${index}].id" value="${lineseg.id?default('')}">
	<td class="listviewTD" align="right">
		<span style="color:red;">*</span>单位:
	</td>
	<td class="listviewContent" align="left">
		<input type="text" class="textTest" readonly="readonly" name="lineSegRegionName${index}" id="lineSegRegionName${index}" value="<#if lineseg?? && lineseg.company??>${lineseg.company.name?default('')}</#if>" datarule="string" datarulejson='{"displayName":"分段地区","dataType":"string","isRequired":"1"}'>
		<input type="hidden" name="fieldMap['${field.name}'].assistantCompanyList[${index}].company.id" id="lineSegRegionId${index}" value="<#if lineseg?? && lineseg.company??>${lineseg.company.id?default('')}</#if>">
		<div id="lineSegRegionDropdownMenu${index}" class="dropDD_contentDiv">
			<div style="overflow:auto;height:266px">
				<ul id="lingSegRegionTree${index}" class="tree"></ul>
			</div>
			<div class="buttonBox" style="position:absolute;bottom:0px;background:#f3f4f4;height:30px;padding-top:4px">
				<a href="javascript:void(0);" class="button" tabindex="-1"><input type="button" onclick="window.curDDWin.saveWin();return false;" value="确认"></a>
				<a href="javascript:void(0);" class="button" tabindex="-1"><input type="button" onclick="lineSegRegionTreeclear('${index}');return false;" value="清空"></a>
			</div>
		</div>
		<script>
		$(function(){
			var setting = {
				asyncUrl : TDQS.CONTEXT_PATH+"company/equaltree.action",
				asyncParam : ["id"],
				async : true,
				callback : {
					click : function(event, treeId, treeNode) {
						$(document.getElementById('lineSegRegionName${index}')).val(treeNode.name);
						$(document.getElementById('lineSegRegionId${index}')).val(treeNode.id);
						window.curDDWin.saveWin();
					},
					loadTreeSuccess : function(zTree, msg) {		
						//zTree.expandAll();
					}
				}
			};
		$(document.getElementById('lingSegRegionTree${index}')).zTree(setting);
		$(document.getElementById('lineSegRegionName${index}')).inputStyle({
			operatorId:"lineSegRegionMenuBtn${index}",
			operatorType:"text",
			operatorText:"选择",
			controllerWidth:'133',
			operatorFun:function(){
					$("input[type='button']",$('.dropDD_contentDiv')).each(function(){
						this.style.backgroundImage="url(./../theme/default/images/main/btn_normal.png)";
						$(this).hover(function(){this.style.backgroundImage="url(./../theme/default/images/main/btn_over.png)";},function(){this.style.backgroundImage="url(./../theme/default/images/main/btn_normal.png)";});
					});
					new DDWin({
						el:"lineSegRegionDropdownMenu${index}"
						,dep:'divAround_lineSegRegionName${index}'
						,clickBody:'save'
					});
				},
			imgFun:function(){
					lineSegRegionTreeclear('${index}');
					window.curDDWin.saveWin();
				}
		});
	});
		</script>
	</td>
	<td class="listviewTD" align="right">
		<span style="color:red;">*</span>线路长度:
	</td>
	<td class="listviewContent" align="left"><input type="text" class="text" style="width:133px;" name="fieldMap['${field.name}'].assistantCompanyList[${index}].length" <#if lineseg.length??>value="${lineseg.length?c}"</#if> datarule="number" datarulejson='{"displayName":"分段长度","dataType":"number","precision":"6","isRequired":"1","length":"8"}' >&nbsp;&nbsp;km</td>
	<td class="listviewContent" colspan="1" align="right"><a href="javascript:void(0);" onclick="removeLineSeg('${index}');return false;">删除</a></td>
	<td class="listviewContent" colspan="1" >&nbsp;</td>
	</tr>
	<#assign index=index+1>
	</#list>
</#if>
<tr class="listviewTR linesegtr">
	<td class="listviewTD" align="left">&nbsp;</td>
	<td class="listviewContent" align="left" colspan="5"><a href="#" class="button" tabindex="-1"><input type="button" onclick="addLineSeg();return false;" value="添加"></a></td>
</tr>

</#if>
